const id = sessionStorage.getItem("Parent_Open_ID")
$.ajax({
    type: 'POST',
    url: DomainName + "/GoodsFileInquiry",
    data: {
        Data: "openid_info"
    },
    success: function (Result) {
        let obj = {}
        obj.name = id
        obj.children = [];
        //1.筛选获得Parent_Open_ID
        Result = Result.filter(function (item) {
            return item.Parent_Open_ID == id
        })
        console.log(Result);
        //2.筛选Open_ID并去重
        let Open_ID = []
        for (let i = 0; i < Result.length; i++) {
            Open_ID.push(Result[i].Open_ID);
        }
        //3.加入到obj.children
        for (let i = 0; i < duplicateRemoval(Open_ID).length; i++) {
            let obj1 = {}
            obj1.name = duplicateRemoval(Open_ID)[i]
            obj1.children = [];
            //4.便利出Route添加到obj2
            for (let j = 0; j < hanshu(duplicateRemoval(Open_ID)[i], Result).length; j++) {
                let obj2 = {}
                obj2.name = hanshu(duplicateRemoval(Open_ID)[i], Result)[j]
                obj1.children.push(obj2)
            }
            obj.children.push(obj1)
        }
        console.log(obj); 
        myChart(obj)
    },
    dataType: "json"
});
function hanshu(Open_ID, Result) {
    let Route = []
    Result = Result.filter(function (item) {
        return item.Open_ID == Open_ID
    })
    for (let i = 0; i < Result.length; i++) {
        Route.push(Result[i].Route);
    }
    return Route
}
//去重
function duplicateRemoval(arr) {
    let newArr = [];
    for (let i = 0; i < arr.length; i++) {
        if (newArr.indexOf(arr[i]) === -1) {
            newArr.push(arr[i]);
        }
    }
    return newArr;
}
function myChart(obj) {
    var dom = document.getElementById('container');
    var myChart = echarts.init(dom, null, {
        renderer: 'canvas',
        useDirtyRect: false
    });
    var option;
    myChart.showLoading();
    myChart.hideLoading();
    obj.children.forEach(function (datum, index) {
        index % 2 === 0 && (datum.collapsed = true);
    });
    myChart.setOption(
        (option = {
            tooltip: {
                trigger: 'item',
                triggerOn: 'mousemove'
            },
            series: [
                {
                    type: 'tree',
                    data: [obj],
                    top: '1%',
                    left: '15%',
                    bottom: '1%',
                    right: '15%',
                    symbolSize: 7,
                    orient: 'RL',
                    label: {
                        position: 'right',
                        verticalAlign: 'middle',
                        align: 'left'
                    },
                    leaves: {
                        label: {
                            position: 'left',
                            verticalAlign: 'middle',
                            align: 'right'
                        }
                    },
                    emphasis: {
                        focus: 'descendant'
                    },
                    expandAndCollapse: true,//是否展开一部分
                    animationDuration: 550,
                    animationDurationUpdate: 750
                }
            ]
        })
    );


    if (option && typeof option === 'object') {
        myChart.setOption(option);
    }

    window.addEventListener('resize', myChart.resize);
}
new Vue({
    el:'#app',
    data(){
        return{
            loading:false
        }
    },
    methods: {
        
    },
})